package com.huawei.petSystemdemo.ui.my;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huawei.petSystemdemo.GlobalViewModel;
import com.huawei.petSystemdemo.R;
import com.huawei.petSystemdemo.bean.Vip;
import com.huawei.petSystemdemo.data.UserRepository;
import com.synnapps.carouselview.CarouselView;
import com.synnapps.carouselview.ImageListener;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.function.Consumer;


public class VipActivity extends AppCompatActivity {
    CarouselView carouselView;

    private ImageView vip_back;
    private TextView vip_name;
    private TextView vip_date;
    private TextView xufei;
    private GlobalViewModel global = GlobalViewModel.getGlobal();
    int[] sampleImages = {R.drawable.keji, R.drawable.dog,R.drawable.keji};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vip);

        vip_back = findViewById(R.id.vip_back);
        vip_name = findViewById(R.id.vip_name);
        vip_date = findViewById(R.id.vip_date);
        xufei = findViewById(R.id.xufei);

        this.getSupportActionBar().hide();


        vip_name.setText(global.user.getUsername());


        carouselView = (CarouselView) findViewById(R.id.carouselView);//轮播图
        carouselView.setPageCount(sampleImages.length);//
        carouselView.setImageListener(imageListener);//

        UserRepository.getVip(global.user.getId(), new Consumer<Vip>() {
            @Override
            public void accept(Vip vip) {
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                vip_date.setText(format.format(vip.getEndDate()));
            }
        });

        xufei.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(VipActivity.this, VipAddActivity.class);
                startActivity(intent);
            }
        });

        vip_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    ImageListener imageListener = new ImageListener() {
        @Override
        public void setImageForPosition(int position, ImageView imageView) {
            imageView.setImageResource(sampleImages[position]);
        }
    };
}